Option Explicit On 
Option Strict On

Imports System.Collections.Specialized

Public Class frmEAover
    Inherits System.Windows.Forms.Form
    Public Shared oEAOver As EAoverClass
    Public Shared bUpdate As Boolean
    Private Shared sOver As String
    Friend WithEvents button_example As System.Windows.Forms.Button
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Private Shared sCites As StringCollection


#Region " Windows Form Designer generated code "

    Public Sub New(ByVal inEAover As EAoverClass)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        oEAOver = inEAover

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtOver As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents lboxCite As System.Windows.Forms.ListBox
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents btnEdit As System.Windows.Forms.Button
    Friend WithEvents btnDelete As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmEAover))
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtOver = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.lboxCite = New System.Windows.Forms.ListBox
        Me.btnAdd = New System.Windows.Forms.Button
        Me.btnEdit = New System.Windows.Forms.Button
        Me.btnDelete = New System.Windows.Forms.Button
        Me.btnOK = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.button_example = New System.Windows.Forms.Button
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(12, 37)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(184, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Entity and Attribute Overview"
        Me.ToolTip1.SetToolTip(Me.Label1, resources.GetString("Label1.ToolTip"))
        '
        'txtOver
        '
        Me.txtOver.Location = New System.Drawing.Point(15, 63)
        Me.txtOver.Multiline = True
        Me.txtOver.Name = "txtOver"
        Me.txtOver.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtOver.Size = New System.Drawing.Size(450, 100)
        Me.txtOver.TabIndex = 1
        Me.ToolTip1.SetToolTip(Me.txtOver, resources.GetString("txtOver.ToolTip"))
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(12, 183)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(216, 23)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Entity and Attribute Detail Citation"
        Me.ToolTip1.SetToolTip(Me.Label2, resources.GetString("Label2.ToolTip"))
        '
        'lboxCite
        '
        Me.lboxCite.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.lboxCite.Location = New System.Drawing.Point(15, 200)
        Me.lboxCite.Name = "lboxCite"
        Me.lboxCite.Size = New System.Drawing.Size(270, 39)
        Me.lboxCite.TabIndex = 4
        Me.ToolTip1.SetToolTip(Me.lboxCite, resources.GetString("lboxCite.ToolTip"))
        '
        'btnAdd
        '
        Me.btnAdd.Image = Global.MetaDoc.My.Resources.Resources.file_new_16x16
        Me.btnAdd.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnAdd.Location = New System.Drawing.Point(48, 245)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(75, 23)
        Me.btnAdd.TabIndex = 5
        Me.btnAdd.Text = "Add"
        '
        'btnEdit
        '
        Me.btnEdit.Enabled = False
        Me.btnEdit.Image = Global.MetaDoc.My.Resources.Resources.file_edit_16x16
        Me.btnEdit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnEdit.Location = New System.Drawing.Point(129, 245)
        Me.btnEdit.Name = "btnEdit"
        Me.btnEdit.Size = New System.Drawing.Size(75, 23)
        Me.btnEdit.TabIndex = 6
        Me.btnEdit.Text = "Edit"
        '
        'btnDelete
        '
        Me.btnDelete.Enabled = False
        Me.btnDelete.Image = Global.MetaDoc.My.Resources.Resources.file_del_16x16
        Me.btnDelete.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnDelete.Location = New System.Drawing.Point(210, 245)
        Me.btnDelete.Name = "btnDelete"
        Me.btnDelete.Size = New System.Drawing.Size(75, 23)
        Me.btnDelete.TabIndex = 7
        Me.btnDelete.Text = "Delete"
        '
        'btnOK
        '
        Me.btnOK.Enabled = False
        Me.btnOK.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnOK.Image = Global.MetaDoc.My.Resources.Resources.Ok_16x16
        Me.btnOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnOK.Location = New System.Drawing.Point(309, 245)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 9
        Me.btnOK.Text = "OK"
        Me.btnOK.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'btnCancel
        '
        Me.btnCancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnCancel.Image = Global.MetaDoc.My.Resources.Resources.Cancel_16x16
        Me.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnCancel.Location = New System.Drawing.Point(390, 245)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 23)
        Me.btnCancel.TabIndex = 10
        Me.btnCancel.Text = "Cancel"
        Me.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'button_example
        '
        Me.button_example.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.button_example.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.button_example.Image = Global.MetaDoc.My.Resources.Resources.app_help_48x48
        Me.button_example.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.button_example.Location = New System.Drawing.Point(362, 12)
        Me.button_example.Name = "button_example"
        Me.button_example.Size = New System.Drawing.Size(110, 48)
        Me.button_example.TabIndex = 21
        Me.button_example.Text = "EXAMPLE"
        Me.button_example.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.button_example.UseVisualStyleBackColor = True
        '
        'ToolTip1
        '
        Me.ToolTip1.IsBalloon = True
        Me.ToolTip1.ShowAlways = True
        Me.ToolTip1.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info
        '
        'frmEAover
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(484, 276)
        Me.ControlBox = False
        Me.Controls.Add(Me.button_example)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.btnDelete)
        Me.Controls.Add(Me.btnEdit)
        Me.Controls.Add(Me.btnAdd)
        Me.Controls.Add(Me.lboxCite)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtOver)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmEAover"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Overview Description"
        Me.ToolTip1.SetToolTip(Me, "summary of, and citation to detailed description of, the information content of t" & _
                "he data set. ")
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub frmEAover_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim iCount As Integer = 0
        Dim iLoop As Integer = 0

        txtOver.Text = oEAOver.Overview
        sCites = oEAOver.DetailCite

        'fill list box with elements from string collection
        lboxCite.Items.Clear() 'make sure start with empty list
        iCount = sCites.Count - 1 'adjust for 0-based index
        For iLoop = 0 To iCount
            lboxCite.Items.Add(sCites(iLoop))
        Next

    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim s1 As String = ""
        Dim frmNewCite As New frmEAcite(s1)
        frmNewCite.ShowDialog()
        If (frmNewCite.getUpdated() = True) Then 'add the new citation
            s1 = frmNewCite.getCite()
            sCites.Add(s1)
            lboxCite.Items.Add(s1)
        End If
        validateOK()
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Dim iCount As Integer = lboxCite.Items.Count
        Dim iSelInd As Integer = lboxCite.SelectedIndex
        Dim s1 As String = ""

        If (iCount = 1) Then iSelInd = 0 'default to edit single value if only one value present
        If (iSelInd = -1) Then
            MessageBox.Show("No detail citation selected for editing", "Selection error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        s1 = sCites(iSelInd) '0-based index
        Dim frmNewCite As New frmEAcite(s1)
        frmNewCite.ShowDialog()
        If (frmNewCite.getUpdated() = True) Then 'add the new citation
            s1 = frmNewCite.getCite()
            sCites.Insert(iSelInd, s1) 'add new version from collection
            sCites.RemoveAt(iSelInd + 1) 'delete old version from collection
            lboxCite.Items.Insert(iSelInd, s1) 'update the list box
            lboxCite.Items.RemoveAt(iSelInd + 1)
        End If
        btnEdit.Enabled = False
        btnDelete.Enabled = False
        validateOK()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim iSelInd As Integer = lboxCite.SelectedIndex

        If (iSelInd = -1) Then
            MessageBox.Show("No detail citation selected for deletion", "Selection error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If

        sCites.RemoveAt(iSelInd) 'update collection
        lboxCite.Items.RemoveAt(iSelInd) 'update list box
        btnEdit.Enabled = False
        btnDelete.Enabled = False
        validateOK()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If (txtOver.Text = "") Then
            MessageBox.Show("Needs the overview information", "Insufficient description", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        Else
            If (sCites.Count = 0) Then
                MessageBox.Show("Needs at least one overview citation", "Insufficient description", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return
            End If
        End If
        oEAOver.Overview = txtOver.Text
        oEAOver.DetailCite = sCites
        bUpdate = True
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        bUpdate = False
        Me.Close()
    End Sub

    Private Sub lboxCite_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lboxCite.SelectedIndexChanged
        If lboxCite.SelectedItems.Count() > 0 Then
            btnEdit.Enabled = True
            btnDelete.Enabled = True
        Else
            btnEdit.Enabled = False
            btnDelete.Enabled = False
        End If
    End Sub

    Private Sub txtOver_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOver.TextChanged
        validateOK()
    End Sub
    Private Sub validateOK()
        If txtOver.Text.Trim() = "" Or lboxCite.Items.Count() = 0 Then btnOK.Enabled = False Else btnOK.Enabled = True
    End Sub

    Public Function getUpdated() As Boolean
        Return bUpdate
    End Function
    Public Function getEAOver() As EAoverClass
        Return oEAOver
    End Function

    Private Sub button_example_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_example.Click
        Dim helpForm As dialog_help = New dialog_help("EAover")
        helpForm.ShowDialog()
    End Sub
End Class
